#!/bin/bash

pgxcInstallDir=$OPENTENBASE_HOME
pgxcOwner=_TABSE_TEST_XXX_YYY_____pgxcOwner
defaultDatabase=postgres
pgxcUser=$pgxcOwner
tmpDir=/tmp
localTmpDir=$tmpDir
configBackup=n
configBackupHost=pgxc-linker
configBackupDir=$HOME/pgxc
configBackupFile=pgxc_ctl.bak
myip=127.1.2.4
rundir=_TABSE_TEST_XXX_YYY_____rundir

clusterMaxMachine=1
clusterMaxParallelQuery=10


#---- GTM ----------
gtmName=gtm
gtmMasterServer=$myip
gtmMasterPort=_TABSE_TEST_XXX_YYY_____gtmMasterPort
gtmMasterDir=$rundir/gtm_master
gtmExtraConfig=none
gtmMasterSpecificExtraConfig=none
gtmSlave=y
gtmSlaveServer=$myip
gtmSlavePort=_TABSE_TEST_XXX_YYY_____gtmSlavePort
gtmSlaveDir=$rundir/gtm_slave
gtmSlaveSpecificExtraConfig=none

gtmProxyDir=$rundir/gtm_pxy
gtmProxy=n
gtmPxyExtraConfig=none
gtmPxySpecificExtraConfig=(none)


#---- Coordinators -------
coordMasterDir=$rundir/coord
coordSlaveDir=$rundir/coord_slave
coordArchLogDir=$rundir/coord_archlog

coordNames=_TABSE_TEST_XXX_YYY_____coordNames
coordPorts=_TABSE_TEST_XXX_YYY_____coordPorts
coordForwardPorts=_TABSE_TEST_XXX_YYY_____coordForwardPorts
poolerPorts=_TABSE_TEST_XXX_YYY_____poolerPorts
coordPgHbaEntries=(0.0.0.0/0)
coordMasterServers=_TABSE_TEST_XXX_YYY_____coordMasterServers
coordMasterDirs=_TABSE_TEST_XXX_YYY_____coordMasterDirs
coordMaxWALsernder=5
coordMaxWALSenders=_TABSE_TEST_XXX_YYY_____coordMaxWALSenders
coordSlave=_TABSE_TEST_XXX_YYY_____coordSlave__
coordSlaveSync=y
coordSlaveServers=_TABSE_TEST_XXX_YYY_____coordSlaveServers
coordSlavePorts=_TABSE_TEST_XXX_YYY_____coordSlavePorts
coordSlavePoolerPorts=_TABSE_TEST_XXX_YYY_____coordSlavePoolerPorts
coordSlaveDirs=_TABSE_TEST_XXX_YYY_____coordSlaveDirs
coordArchLogDirs=_TABSE_TEST_XXX_YYY_____coordArchLogDirs

#coordAdditionalSlaves=y
#coordAdditionalSlaveSet=(cad1)
#cad1_Sync=y
#cad1_Servers=($myip $myip $myip)  # Hosts
#cad1_dir=$coordMasterDir/coord_slave_cad1
#cad1_Dirs=($cad1_dir/cn1 $cad1_dir/cn2 $cad1_dir/cn3)
#cad1_ArchLogDir=$coordArchLogDir/cad1_arch
#cad1_ArchLogDirs=($cad1_ArchLogDir/cn1 $cad1_ArchLogDir/cn2 $cad1_ArchLogDir/cn3)


coordExtraConfig=coordExtraConfig
cat > $coordExtraConfig <<EOF
#================================================
# Added to all the coordinator postgresql.conf
# Original: $coordExtraConfig

enable_datanode_row_triggers = on
wal_level = hot_standby
wal_keep_segments = 256
max_wal_senders = 4
archive_mode = on
archive_timeout = 1800
archive_command = 'echo 0'
log_truncate_on_rotation = on
log_filename = 'postgresql-%A-%H.log'
log_rotation_age = 4h
log_rotation_size = 0
hot_standby = on
wal_sender_timeout = 30min
wal_receiver_timeout = 30min
max_pool_size = 400
log_statement = 'all'
log_destination = 'csvlog'
logging_collector = on
log_directory = 'pg_log'
listen_addresses = '*'
max_connections = 500
#max_parallel_workers_per_gather=4
fn_send_shared_buffer_size=1GB
fn_recv_shared_buffer_size=1GB
vacuum_delta = 2000
snapshot_for_analyze = false
shared_buffers='512MB'
shared_preload_libraries = 'pg_plan_advsr'
page_checksums = false
EOF

coordSpecificExtraConfig=(none)
coordExtraPgHba=none
coordSpecificExtraPgHba=(none)
coordAdditionalSlaves=n
cad1_Sync=n

#---- Datanodes ---------------------
dnMstrDir=$rundir/dn_master
dnSlvDir=$rundir/dn_slave
dnALDir=$rundir/datanode_archlog

primaryDatanode=dn001
datanodeNames=_TABSE_TEST_XXX_YYY_____datanodeNames
datanodePorts=_TABSE_TEST_XXX_YYY_____datanodePorts
datanodeForwardPorts=_TABSE_TEST_XXX_YYY_____datanodeForwardPorts
datanodePoolerPorts=_TABSE_TEST_XXX_YYY_____datanodePoolerPorts
datanodePgHbaEntries=(0.0.0.0/0)
datanodeMasterServers=_TABSE_TEST_XXX_YYY_____datanodeMasterServers
datanodeMasterDirs=_TABSE_TEST_XXX_YYY_____datanodeMasterDirs
dnWALSndr=5
datanodeMaxWALSenders=_TABSE_TEST_XXX_YYY_____datanodeMaxWALSenders

datanodeSlave=_TABSE_TEST_XXX_YYY_____datanodeSlave__
datanodeSlaveServers=_TABSE_TEST_XXX_YYY_____datanodeSlaveServers
datanodeSlavePorts=_TABSE_TEST_XXX_YYY_____datanodeSlavePorts
datanodeSlavePoolerPorts=_TABSE_TEST_XXX_YYY_____datanodeSlavePoolerPorts
datanodeSlaveSync=y
datanodeSlaveDirs=_TABSE_TEST_XXX_YYY_____datanodeSlaveDirs
datanodeArchLogDirs=_TABSE_TEST_XXX_YYY_____datanodeArchLogDirs

datanodeExtraConfig=datanodeExtraConfig
coordExtraConfig=datanodeExtraConfig
cat > $datanodeExtraConfig <<EOF
#================================================
# Added to all the coordinator postgresql.conf
# Original: $datanodeExtraConfig

enable_datanode_row_triggers = on
listen_addresses = '*'
wal_level = hot_standby
wal_keep_segments = 256
max_wal_senders = 4
archive_mode = on
archive_timeout = 1800
archive_command = 'echo 0'
log_directory = 'pg_log'
logging_collector = on
log_truncate_on_rotation = on
log_filename = 'postgresql-%A-%H.log'
log_rotation_age = 4h
log_rotation_size = 0
hot_standby = on
wal_sender_timeout = 30min
wal_receiver_timeout = 30min
shared_buffers = 16MB
max_connections = 500
max_pool_size = 2000
log_statement = 'all'
log_destination = 'csvlog'
#max_parallel_workers_per_gather=4
vacuum_delta = 2000
shared_preload_libraries = 'pg_stat_statements'
snapshot_for_analyze = false
enable_bitmapscan = false
enable_material = false
shared_buffers='2GB'
page_checksums = false
EOF

datanodeSpecificExtraConfig=(none)
datanodeSpecificExtraPgHba=(none)
datanodeExtraPgHba=datanodeExtraPgHba
cat > $datanodeExtraPgHba <<EOF

local   all             all                                     trust
host    all             all             0.0.0.0/0               trust
host    replication     all             0.0.0.0/0               trust
host    all             all             ::1/128                 trust
host    replication     all             ::1/128                 trust


EOF


datanodeAdditionalSlaves=n
walArchive=n
